package com.mapapp.flutter_mapapp.application;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.support.multidex.MultiDex;

import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;
import com.mapapp.flutter_mapapp.bean.DaoMaster;
import com.mapapp.flutter_mapapp.bean.DaoSession;
import com.mapapp.flutter_mapapp.bean.MapDetailBean;
import com.mapapp.flutter_mapapp.util.DensityUtil;
import com.mapapp.flutter_mapapp.util.ScreenUtil;
import com.umeng.commonsdk.UMConfigure;

public class MyApplication extends Application {
    private static MyApplication instance;

    public static MyApplication getInstance() {
        return instance;
    }

    private DaoMaster.DevOpenHelper mHelper;
    private SQLiteDatabase db;
    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;
    public static MapDetailBean mSearchResult = null;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        //获取设备信息
        printDevInfo();

        UMConfigure.init(this, "5e350ca8570df35c780000d7", "Umeng", UMConfigure.DEVICE_TYPE_PHONE, null);

        //在使用SDK各组件之前初始化context信息，传入ApplicationContext
        SDKInitializer.initialize(this);
        //自4.3.0起，百度地图SDK所有接口均支持百度坐标和国测局坐标，用此方法设置您使用的坐标类型.
        //包括BD09LL和GCJ02两种坐标，默认是BD09LL坐标。
        SDKInitializer.setCoordType(CoordType.BD09LL);

        setDatabase();
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    private void setDatabase() {
        mHelper = new DaoMaster.DevOpenHelper(this, "notes-db", null);
        db = mHelper.getWritableDatabase();
        mDaoMaster = new DaoMaster(db);
        mDaoSession = mDaoMaster.newSession();
    }

    public DaoSession getDaoSession() {
        return mDaoSession;
    }

    public SQLiteDatabase getDb() {
        return db;
    }


    private void printDevInfo() {
        DensityUtil mDensity = new DensityUtil(this);
        System.out.println("-------device info start-------------");
        System.out.println("the device dpi:" + DensityUtil.getDmDensityDpi());
        System.out.println("the device density scale:"
                + DensityUtil.getDmDensithScale());
        System.out.println("screen width:" + ScreenUtil.getScreenWidth(this));
        System.out.println("screen height:" + ScreenUtil.getScreenHeight(this));
        System.out.println("screen status bar height:"
                + ScreenUtil.getStatusHeight(this));
        System.out.println("-------device info end-------------");
    }
}
